<?php

namespace App\Model;

class UserWalletcodeModel extends BaseModel
{
    protected $table = 'user_walletcode';

    protected $primaryKey = 'user_walletcode_id';

    public static $walletcodeStatusMap = [
        'init' => 0,                         //充值中
        'success' => 1,                         //充值成功
        'error' => 2,                          //充值失败
        'abnormal' => 3,                        //充值异常
    ];

    /**
     * 创建
     * @param $data
     * @return bool|mixed
     */
    public static function createUserWalletcode($data)
    {
        $model = new self ();
        $model->walletcode_no = $data['walletcode_no'];
        $model->walletcode = $data['walletcode'];
        $model->client_no = $data['client_no'];
        $model->bot_id = $data['bot_id'];
        $model->steam_id = $data['steam_id'];
        $model->walletcode_status = 0;
        if (!$model->save()) {
            return false;
        }
        $userWalletcodeId = $model->user_walletcode_id;
        return $userWalletcodeId;
    }

    /**
     * 通过user_walletcode_id获取steam钱包充值记录
     * @param $userWalletcodeId
     * @return array
     */
    public static function getUserWalletcodeByUserWalletcodeId($userWalletcodeId)
    {
        $where = array(
            'user_walletcode_id' => $userWalletcodeId,
        );

        $result = static::where($where)->first();

        return $result ? $result->toArray() : [];
    }
}